package com.yanxu.design01_singleton.destroy.reflection_destory.lazy;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2025/4/14-2025
 * @Description: 懒汉式单例模式
 */
public class LazyInstance {
    private static volatile LazyInstance lazyInstance = null;
    private static  boolean flag = true;

    private LazyInstance() {
        if (flag){
            flag = false;
        }else {
            throw new RuntimeException("LazyInstance not allow reflection create!!!");
        }
    }

    public static LazyInstance getInstance() {
        if (lazyInstance == null) {
            synchronized (LazyInstance.class) {
                if (lazyInstance == null) {
                    lazyInstance = new LazyInstance();
                }
            }
        }
        return lazyInstance;
    }
}